package com.gitbl.webchat.server;

import com.gitbl.webchat.db.DbUtils;
import com.gitbl.webchat.utils.ArgumentsHelper;
import groovyjarjarcommonscli.ParseException;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;

import java.io.IOException;
import java.util.HashSet;
import java.util.Properties;

//import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;

//@SpringBootApplication
@EnableAutoConfiguration
public class Application {

    public static void main(String[] args) throws IOException, ParseException {

        HashSet<String> systemproperties=new HashSet();
        systemproperties.add("DUBBO_IP_TO_REGISTRY");
        systemproperties.add("DDUBBO_PORT_TO_REGISTRY");
        systemproperties.add("DUBBO_PORT_TO_BIND");
        Properties pps = ArgumentsHelper.parseProperties(args, "use value for given property(property=value) \neg: -Dzk=192.168.10.144:2181,192.168.10.144:2082" +
                "\\\n-Ddb.host=localhost:3306" +
                "\\\n-Ddb.user=root" +
                "\\\n-Ddb.pwd=" +
                "\\\b-DDUBBO_IP_TO_REGISTRY=192.168.1.102" +
                "\\\b-DDUBBO_PORT_TO_REGISTRY=20880" +
                "\\\b-DDUBBO_PORT_TO_BIND=20880","webchat-provider-user-1.0-SNAPSHOT.jar");
        if(pps==null){
            return;
        }
        DbUtils.properties = pps;
        for (Object p : pps.keySet()) {
            String k = p.toString();
            if(systemproperties.contains(k))
                System.setProperty(k, pps.getProperty(p.toString()));
        }

        UserServer u = new UserServer();
        boolean ex = u.exist("cxx");

        new SpringApplicationBuilder(Application.class)
                .run(args);



        /*
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:dubbo-provider-user.xml");

        context.start();
        //SpringApplication.run(App.class, args);
        while (true){
            if(System.in.read()=='q'){
                System.out.println("exit");
                context.stop();
                break;
            }
        }
        */
    }





}
